{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from sklearn.cluster import KMeans\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# 载入数据\n",
    "data = np.genfromtxt(\"kmeans.txt\", delimiter=\" \")\n",
    "# 设置k值\n",
    "k = 4  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "KMeans(algorithm='auto', copy_x=True, init='k-means++', max_iter=300,\n",
       "    n_clusters=4, n_init=10, n_jobs=1, precompute_distances='auto',\n",
       "    random_state=None, tol=0.0001, verbose=0)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 训练模型\n",
    "model = KMeans(n_clusters=k)\n",
    "model.fit(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 2.6265299   3.10868015]\n",
      " [-3.38237045 -2.9473363 ]\n",
      " [-2.46154315  2.78737555]\n",
      " [ 2.80293085 -2.7315146 ]]\n"
     ]
    }
   ],
   "source": [
    "# 分类中心点坐标\n",
    "centers = model.cluster_centers_\n",
    "print(centers)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 2 3 1 0 2 3 1 0 2 3 1 0 2 3 1 0 2 3 1 0 2 3 1 0 2 3 1 0 2 3 1 0 2 3 1 0\n",
      " 2 3 1 0 2 3 1 0 2 3 1 0 2 3 1 0 2 3 1 0 2 3 1 0 2 3 1 0 2 3 1 0 2 3 1 0 2\n",
      " 3 1 0 2 3 1]\n"
     ]
    }
   ],
   "source": [
    "# 预测结果\n",
    "result = model.predict(data)\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 2, 3, 1, 0, 2, 3, 1, 0, 2, 3, 1, 0, 2, 3, 1, 0, 2, 3, 1, 0, 2,\n",
       "       3, 1, 0, 2, 3, 1, 0, 2, 3, 1, 0, 2, 3, 1, 0, 2, 3, 1, 0, 2, 3, 1,\n",
       "       0, 2, 3, 1, 0, 2, 3, 1, 0, 2, 3, 1, 0, 2, 3, 1, 0, 2, 3, 1, 0, 2,\n",
       "       3, 1, 0, 2, 3, 1, 0, 2, 3, 1, 0, 2, 3, 1])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.labels_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXYAAAD8CAYAAABjAo9vAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAHBpJREFUeJzt3X9sXNWVB/DvGcdx7LgkIvEaFeIZ\n0kZRo/woG6ttWlWlhawopbCUCtFOaAFprZZWIgKWbXC1VcpaixKpTaX+krsLispIkADZbFCqloZG\nq5XSLaYlQGICKLVT+iMdzK+kdhLbc/aP50k84zczb2bej/vu+34kazLPM2/ueODMffeee66oKoiI\nyB6pqBtARET+YmAnIrIMAzsRkWUY2ImILMPATkRkGQZ2IiLLMLATEVmGgZ2IyDIM7ERElpkXxYsu\nXbpUM5lMFC9NRBRbzz333Buq2lXrcZEE9kwmg6Gho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qvAN9vLHGMnYjIMuyxExFZhoE9YCJy\nr4ioiCyNui1BEpHtIvKyiLwgIntEZHHUbfKbiFwjIsdE5DUR+UbU7QmSiCwTkV+JyLCIHBGRu6Ju\nU9BEpEVEficiT0XdlmYxsAdIRJYB2AggCfsMPQ1gtaquBfAKgC0Rt8dXItIC4AcAPg1gFYAviMiq\naFsVqCkA96jqBwB8BMDXLH+/AHAXgOGoG+EHBvZgfRfAfQCsn8hQ1V+o6tTM3V8DuCzK9gTgQwBe\nU9XjqnoOwKMAboi4TYFR1T+r6m9n/n0KTsC7NNpWBUdELgPwGQD/EXVb/MDAHhARuR7AH1X1cNRt\nicAdAH4WdSN8dimAP8y6/zosDnSziUgGwBUA/i/algRqB5xOWCHqhviBG200QUR+CeASl1/1A7gf\nwD+E26JgVXu/qrp35jH9cC7jc2G2LQTicsz6KzER6QTwBIDNqvpu1O0JgohcB+CvqvqciFwZdXv8\nwMDeBFW92u24iKwBcDmAwyICOMMSvxWRD6nqX0Jsoq8qvd8iEfkygOsAXKX25dG+DmDZrPuXAfhT\nRG0JhYi0wgnqOVV9Mur2BOhjAK4XkWsBLABwkYg8oqqbIm5Xw5jHHgIRGQHQq6omFxdqiohcA+A7\nAD6hqvmo2+M3EZkHZ1L4KgB/BPAsgC+q6pFIGxYQcXokOwG8qaqbo25PWGZ67Peq6nVRt6UZHGMn\nv3wfwHsAPC0iz4vIj6NukJ9mJoa/DuDncCYSd9ka1Gd8DMCtAD4183k+P9OjpRhgj52IyDLssRMR\nWYaBnYjIMgzsRESWYWAnIrIMAzsRkWUY2ImILMPATkRkGQZ2IiLL/D8rSu5DiFKaywAAAABJRU5E\nrkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1e822545b00>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画出各个数据点，用不同颜色表示分类\n",
    "mark = ['or', 'ob', 'og', 'oy']\n",
    "for i,d in enumerate(data):\n",
    "    plt.plot(d[0], d[1], mark[result[i]])\n",
    "\n",
    "# 画出各个分类的中心点\n",
    "mark = ['*r', '*b', '*g', '*y']\n",
    "for i,center in enumerate(centers):\n",
    "    plt.plot(center[0],center[1], mark[i], markersize=20)\n",
    "    \n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXYAAAD8CAYAAABjAo9vAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAH0VJREFUeJzt3XuQXNV9J/Dvr7tnNJr3jGaQEKMH\noEiGYBPhAVM2wjJgIIChynGqsmwSK65EiR178W4c1g5VjlOVqqXWKdtU2d6NijgksRxIYhzHwQmP\nOErEJmAEGBMhUCTBIKHHSKN5v2f6t39092get7vv7T6377nnfj9VFEzP1e3TkvjeM7/zu+eKqoKI\niNyRinoARERkFoOdiMgxDHYiIscw2ImIHMNgJyJyDIOdiMgxDHYiIscw2ImIHMNgJyJyTMbESUSk\nHcDDAK4CoAA+oar/Xuz4dEuTZro6TLw1UegaTsxEPQQiAMDI3Nlzqtpd7jgjwQ7gIQD/qKofE5F6\nAI0l37SrAxd/6TOG3pooXF3769D9xNGoh0GEfzz9zT4/x1Ud7CLSCuBGALsAQFVnAHCKQ0QUERM1\n9ssAnAXwpyLysog8LCJNBs5LREQVMBHsGQDXAPg/qrodwDiAzy8/SER2i8gBETkwPzpu4G2JiMiL\niWA/AeCEqj6f//pvkAv6JVR1j6r2qmpvuoUTeiKisFQd7Kp6GsBxEdmWf+lmAK9Ve14iW4xukqiH\nQBSIqa6YzwDYm++IOQbg1wydlyhy0xvZC0DxYiTYVfUnAHpNnIuIiKrDO0+JiBzDYCcicgyDnYjI\nMQx2IiLHM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zbqgdRSJuoBAICIPANgnce3HkBujB3I/Zh4LYC/EpHL\nNCbtPGU+2+8BuLW2IzKn1GdT1e/nj3kAuR/399ZybCEQj9di8XfQDxFpBvBdAJ9V1ZGox2OCiNwF\noF9VXxSRnVGPp5asCHZVvaXY90TkkwAezwf5j0Uki9y+D2drNb5qFPtsIvJuAJcCeEVEgFyp4iUR\nuU5VT9dwiBUr9ecGACLycQB3Abg5LhfiEk4A2LDo6x4AJyMai1EiUodcqO9V1cejHo9BHwBwt4jc\nAaABQKuIfFtVfznicYXO+j52EfktAOtV9YsishXAPwHY6EBQLCEibwHoVVUXNiqCiNwO4CsAPqiq\nsbgIlyIiGeQWgW8G8A6AFwDcq6oHIx1YlSQ3q/gzAOdV9bNRjycs+Rn751T1rqjHUgtxqLF/C8Bl\nIvIfyC1Yfdy1UHfU1wG0AHhaRH4iIv836gFVI78Q/GkATyK3wPhXcQ/1vA8A+BUAN+X/nH6Sn+FS\njFk/YyciomDiMGMnIqIAGOxERI5hsBMROYbBTkTkGAY7EZFjGOxERI5hsBMROYbBTkTkmP8PWSJo\nN05P/hIAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1e818727eb8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 获取数据值所在的范围\n",
    "x_min, x_max = data[:, 0].min() - 1, data[:, 0].max() + 1\n",
    "y_min, y_max = data[:, 1].min() - 1, data[:, 1].max() + 1\n",
    "\n",
    "# 生成网格矩阵\n",
    "xx, yy = np.meshgrid(np.arange(x_min, x_max, 0.02),\n",
    "                     np.arange(y_min, y_max, 0.02))\n",
    "\n",
    "z = model.predict(np.c_[xx.ravel(), yy.ravel()])# ravel与flatten类似，多维数据转一维。flatten不会改变原始数据，ravel会改变原始数据\n",
    "z = z.reshape(xx.shape)\n",
    "# 等高线图\n",
    "cs = plt.contourf(xx, yy, z)\n",
    "# 显示结果\n",
    "# 画出各个数据点，用不同颜色表示分类\n",
    "mark = ['or', 'ob', 'og', 'oy']\n",
    "for i,d in enumerate(data):\n",
    "    plt.plot(d[0], d[1], mark[result[i]])\n",
    "\n",
    "# 画出各个分类的中心点\n",
    "mark = ['*r', '*b', '*g', '*y']\n",
    "for i,center in enumerate(centers):\n",
    "    plt.plot(center[0],center[1], mark[i], markersize=20)\n",
    "    \n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
